import Vue from 'vue'
import VueRouter from 'vue-router'
import About from '../views/About.vue'
import Helloworld from '../components/HelloWorld'
import chatroom from '../components/app/chatroom'
import user from '../components/app/user'
import data_log from '../components/data/data_log'
import analysis from '../components/data/analysis'
import log from '../components/logs/log'
import right from '../components/rights/myright'
import myright from '../components/rights/right'
import users from '../components/rights/users'
import content from '../components/app/content'
import list from '../components/app/list'
import login from '../views/login'

Vue.use(VueRouter)

  const routes = [
  
  {path:'/', redirect:'/login'},
  {path: '/login',component: login},
  {path: '/about',component: About},
  {
    path:'/helloworld',
    component:Helloworld,
    children:[
      {path:'/chatroom',component:chatroom},
      {path:'/user',component:user},
      {path:'/data_log',component:data_log},
      {path:'/analysis',component:analysis},
      {path:'/log',component:log},
      {path:'/right',component:right},
      {path:'/users',component:users},
      {path:'/content',component:content},
      {path:'/list',component:list},
      {path:'/myright',component:myright}

    ]
  },
 
]

const router = new VueRouter({
  //mode: 'history',
  routes
})

// 挂载路由导航守卫
router.beforeEach((to,from,next)=>{
//to  将要访问 from哪里来 next放行
//next        next('/home')强制跳转
if(to.path=='/login') return next();
//获取token
const tokenStr=window.sessionStorage.getItem('token')
if(!tokenStr) return next('/login')
else next()
})
export default router
